home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qlistbox.h.z / qlistbox.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  6.2 KB  |  244 lines

  1. /**********************************************************************
  2. ** $Id: qlistbox.h,v 2.17 1998/07/03 00:09:49 hanord Exp $
  3. **
  4. ** Definition of QListBox widget class
  5. **
  6. ** Created : 941121
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QLISTBOX_H
  25. #define QLISTBOX_H
  26.  
  27. #ifndef QT_H
  28. #include "qtableview.h"
  29. #include "qpixmap.h"
  30. #endif // QT_H
  31.  
  32.  
  33. #define LBI_Undefined    0            // list box item types
  34. #define LBI_Text    1
  35. #define LBI_Pixmap    2
  36. #define LBI_UserDefined 1000
  37.  
  38.  
  39. class QStrList;
  40. class QLBItemList;
  41.  
  42. class QListBox;
  43.  
  44.  
  45. class QListBoxItem
  46. {
  47. public:
  48.     QListBoxItem();
  49.     virtual ~QListBoxItem();
  50.  
  51.     virtual const char      *text()   const { return txt; }
  52.     virtual const QPixmap *pixmap() const { return 0; }
  53.  
  54.     virtual int     height( const QListBox * ) const = 0;
  55.     virtual int     width( const QListBox * )  const = 0;
  56.  
  57. protected:
  58.     virtual void paint( QPainter * ) = 0;
  59.     void     setText( const char *text ) { txt = text; }
  60.  
  61. private:
  62.     QString txt;
  63.     bool selected;
  64.  
  65.     friend class QListBox;
  66.  
  67. private:    // Disabled copy constructor and operator=
  68.     QListBoxItem( const QListBoxItem & );
  69.     QListBoxItem &operator=( const QListBoxItem & );
  70. };
  71.  
  72.  
  73. class QListBoxText : public QListBoxItem
  74. {
  75. public:
  76.     QListBoxText( const char * = 0 );
  77.    ~QListBoxText();
  78.     void  paint( QPainter * );
  79.     int      height( const QListBox * ) const;
  80.     int      width( const QListBox * )  const;
  81. private:    // Disabled copy constructor and operator=
  82.     QListBoxText( const QListBoxText & );
  83.     QListBoxText &operator=( const QListBoxText & );
  84. };
  85.  
  86.  
  87. class QListBoxPixmap : public QListBoxItem
  88. {
  89. public:
  90.     QListBoxPixmap( const QPixmap & );
  91.    ~QListBoxPixmap();
  92.     const QPixmap *pixmap() const { return ± }
  93. protected:
  94.     void paint( QPainter * );
  95.     int height( const QListBox * ) const;
  96.     int width( const QListBox * ) const;
  97. private:
  98.     QPixmap pm;
  99. private:    // Disabled copy constructor and operator=
  100.     QListBoxPixmap( const QListBoxPixmap & );
  101.     QListBoxPixmap &operator=( const QListBoxPixmap & );
  102. };
  103.  
  104.  
  105. class QListBox : public QTableView        // list box widget
  106. {
  107.     Q_OBJECT
  108. public:
  109.     QListBox( QWidget *parent=0, const char *name=0, WFlags f=0  );
  110.    ~QListBox();
  111.  
  112.     void    setFont( const QFont & );
  113.  
  114.     uint    count() const;
  115.  
  116.     void    insertStrList( const QStrList *, int index=-1 );
  117.     void    insertStrList( const char**, int numStrings=-1, int index=-1 );
  118.  
  119.     void    insertItem( const QListBoxItem *, int index=-1 );
  120.     void    insertItem( const char *text, int index=-1 );
  121.     void    insertItem( const QPixmap &pixmap, int index=-1 );
  122.     void    inSort( const QListBoxItem * );
  123.     void    inSort( const char *text );
  124.  
  125.     void    removeItem( int index );
  126.     void    clear();
  127.  
  128.     const char *text( int index )    const;
  129.     const QPixmap *pixmap( int index )    const;
  130.  
  131.     void    changeItem( const QListBoxItem *, int index );
  132.     void    changeItem( const char *text, int index );
  133.     void    changeItem( const QPixmap &pixmap, int index );
  134.  
  135.     bool    autoUpdate()    const;
  136.     void    setAutoUpdate( bool );
  137.  
  138.     int        numItemsVisible() const;
  139.     void    setFixedVisibleLines( int lines );
  140.  
  141.     int        currentItem()    const;
  142.     void    setCurrentItem( int index );
  143.     void    centerCurrentItem();
  144.     int        topItem()    const;
  145.     void    setTopItem( int index );
  146.  
  147.     bool    dragSelect()        const;
  148.     void    setDragSelect( bool );
  149.     bool    autoScroll()        const;
  150.     void    setAutoScroll( bool );
  151.     bool    autoScrollBar()        const;
  152.     void    setAutoScrollBar( bool );
  153.     bool    scrollBar()        const;
  154.     void    setScrollBar( bool );
  155.     bool    autoBottomScrollBar()    const;
  156.     void    setAutoBottomScrollBar( bool );
  157.     bool    bottomScrollBar()    const;
  158.     void    setBottomScrollBar( bool );
  159.     bool    smoothScrolling()    const;
  160.     void    setSmoothScrolling( bool );
  161.  
  162.     int        itemHeight()        const;
  163.     int        itemHeight( int index ) const;
  164.  
  165.     long    maxItemWidth() const;
  166.     long    maxItemWidth(); // only for bin. compat
  167.  
  168.     bool    isMultiSelection() const;
  169.     void    setMultiSelection( bool );
  170.  
  171.     void    setSelected( int, bool );
  172.     bool    isSelected( int ) const;
  173.  
  174.     QSize    sizeHint() const;
  175.  
  176. public slots:
  177.     void    clearSelection();
  178.  
  179. signals:
  180.     void    highlighted( int index );
  181.     void    selected( int index );
  182.     void    highlighted( const char * );
  183.     void    selected( const char * );
  184.  
  185.     void    selectionChanged();
  186.  
  187. protected:
  188.     QListBoxItem *item( int index ) const;
  189.     bool    itemVisible( int index );
  190.  
  191.     int        cellHeight( int index = 0 );
  192.     void    paintCell( QPainter *, int row, int col );
  193.  
  194.     void    mousePressEvent( QMouseEvent * );
  195.     void    mouseReleaseEvent( QMouseEvent * );
  196.     void    mouseDoubleClickEvent( QMouseEvent * );
  197.     void    mouseMoveEvent( QMouseEvent * );
  198.     void    keyPressEvent( QKeyEvent *e );
  199.     void    focusInEvent( QFocusEvent *e );
  200.     void    focusOutEvent( QFocusEvent *e );
  201.     void    resizeEvent( QResizeEvent * );
  202.     void    timerEvent( QTimerEvent * );
  203.  
  204.     int        findItem( int yPos ) const;
  205.     bool    itemYPos( int index, int *yPos ) const;
  206.     void    updateItem( int index, bool clear = TRUE );
  207.     void    clearList();
  208.     void    updateCellWidth();
  209.  
  210.     void    toggleCurrentItem();
  211.  
  212. private:
  213.     void    updateNumRows( bool );
  214.     void    insert( const QListBoxItem *, int, bool );
  215.     void    change( const QListBoxItem *lbi, int );
  216.     void    setMaxItemWidth( int );
  217.     void    ensureCurrentVisible( int = -1 );
  218.  
  219.     void    emitChangedSignal( bool );
  220.  
  221.     uint    doDrag        : 1;
  222.     uint    doAutoScroll    : 1;
  223.     uint    isTiming    : 1;
  224.     uint    scrollDown    : 1;
  225.     uint    stringsOnly    : 1;
  226.     uint    multiSelect    : 1;
  227.     uint    goingDown    : 1;
  228.     int        current;
  229.     QLBItemList *itemList;
  230.  
  231. private:    // Disabled copy constructor and operator=
  232.     QListBox( const QListBox & );
  233.     QListBox &operator=( const QListBox & );
  234. };
  235.  
  236.  
  237. inline bool QListBox::isMultiSelection() const
  238. {
  239.     return multiSelect;
  240. }
  241.  
  242.  
  243. #endif // QLISTBOX_H
  244.